<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../js/vue.js"></script>
</head>
<style>
    .active {
        color: cornflowerblue;
    }

    .danger {
        color: red;
    }
</style>

<body>
    <div id="app-2">
        <span v-bind:title="message">
            鼠标悬停几秒钟查看此处动态绑定的提示信息！
        </span>
        <div class="status" :class="{ active: isActive, danger: hasError }">
            哈哈哈哈
        </div>
        <div class="status" :class="classObj">
            嘿嘿嘿嘿嘿
        </div>
        <div class="status" :class="classObject">
            嘻嘻嘻想
        </div>
    </div>
</body>
<script>
    var app2 = new Vue({
        el: '#app-2',
        data: {
            message: '页面加载于 ' + new Date().toLocaleString(),
            isActive: true,
            hasError: false,
            classObj: {
                active: false,
                danger: true,
            }
        },
        computed: {
            classObject: function () {
                return {
                    active: this.isActive && !this.hasError,
                    danger: this.hasError && this.hasError.type === 'fatal'
                }
            }
        }
    })
</script>

</html>